package org.ricks.action.rpc;

import org.ricks.net.action.context.FlowContext;
import org.ricks.net.action.context.head.RpcHeadMeta;
import org.ricks.net.extension.plugins.HeartPlugin;
import org.ricks.net.transport.AioSession;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class RpcHeartHandler extends HeartPlugin<FlowContext<RpcHeadMeta>> {

    private static final short CMD_HEARTBEAT = 0;
    public static final RpcHeadMeta HEARTBEAT_HEADER = new RpcHeadMeta(CMD_HEARTBEAT, false, true, 0);


    public RpcHeartHandler(int heartRate, int timeout, TimeUnit timeUnit, TimeoutCallback timeoutCallback) {
        super(heartRate, timeout, timeUnit, timeoutCallback);
    }

    @Override
    public void sendHeartRequest(AioSession session) throws IOException {
//        session.writeBuffer()/
    }

    @Override
    public boolean isHeartMessage(AioSession session, FlowContext<RpcHeadMeta> msg) {
        return (msg.headMeta.flags() & RpcHeadMeta.FLAG_HEARTBEAT) != 0 ;
    }
}
